package com.computergames.server.server.session;

import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.*;

@Data
public class Room implements Serializable {
    // 房间名称
    private String name;
    // 房间类型
    private String roomType;
    // 房间成员
    private List<String> members;
    // 当前房间人数
    private int currentPlayers;
    // 最大房间人数
    private int maxPlayers;

    private Set<String> memberSet;

    private Map<String, Object> roomData = new HashMap<>();

    public static final Room EMPTY_ROOM = new Room("empty", "empty", Collections.emptyList(), 0, 0);

    public Room(String name, String roomType, List<String> members, int currentPlayers, int maxPlayers) {
        this.name = name;
        this.roomType = roomType;
        this.members = members;
        this.currentPlayers = currentPlayers;
        this.maxPlayers = maxPlayers;
        // 创建一个 Set 用于存储，以去除可能的重复并符合预期的存储类型
        this.memberSet = new HashSet<>(members);
        roomData.put("name", this.getName());
        roomData.put("roomType", this.getRoomType());
        roomData.put("members", this.getMemberSet());
        roomData.put("currentPlayers", this.getMembers().size());
        roomData.put("maxPlayers", this.getMaxPlayers());
    }
    @Override
    public String toString() {
        return "Room{" +
                "name='" + name + '\'' +
                ", roomType='" + roomType + '\'' +
                ", members=" + members +
                ", currentPlayers=" + currentPlayers +
                ", maxPlayers=" + maxPlayers +
                '}';
    }

}
